package com.woniuxy.commons.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class QueueConfig {


    @Bean
    public Queue UserRegisterQueue(){
        return new Queue("user_register_queue");
    }

    @Bean
    public Queue UserLoginQueue(){
        return new Queue("user_login_queue");
    }

    @Bean
    public Queue MemberOpenQueue(){
        return new Queue("member_open_queue");
    }

    @Bean
    public DirectExchange orderCheckExchange(){
        return new DirectExchange("order_check_exchange");
    }

    @Bean
    public Binding orderCheckBinding(){
        return BindingBuilder.bind(orderCheckQueue()).to(orderCheckExchange()).with("order");
    }

    @Bean
    public DirectExchange serviceOrderCheckExchange(){
        return new DirectExchange("service_order_check_exchange");
    }
    @Bean
    public Binding serviceOrderCheckBinding(){
        return BindingBuilder.bind(serviceOrderCheckQueue()).to(serviceOrderCheckExchange()).with("serviceOrder");
    }

//    @Bean
//    public Binding memberOrderCheckBinding(){
//        return BindingBuilder.bind(memberOrderCheckQueue()).to(orderCheckExchange()).with("memberOrder");
//    }

    @Bean
    public Queue orderCheckQueue(){
        return new Queue("order_check_queue");
    }

    @Bean
    public Queue serviceOrderCheckQueue(){
        return new Queue("serviceOrder_check_queue");
    }

    @Bean
    public Queue tk(){
        return new Queue("order_tk_queue");
    }

//    @Bean
//    public Queue memberOrderCheckQueue(){
//        return new Queue("memberOrder_check_queue");
//    }

    @Bean
    public Queue orderCheckDelayQueue(){
        Map<String, Object> params = new HashMap<>();
        //定义该队列中消息的生存时间 单位毫秒 生存时间最终对应业务的延迟执行时间
        params.put("x-message-ttl", 60 * 1000*15);
        // x-dead-letter-exchange 属性用于声明死信转发到的交换机
        params.put("x-dead-letter-exchange", "order_check_exchange");
        // x-dead-letter-routing-key 声明了这些死信在转发时携带的路由键名称。
        params.put("x-dead-letter-routing-key", "order");
        return new Queue("order_check_delay_queue", true, false, false, params);
    }

//    @Bean
//    public Queue memberOrderCheckDelayQueue(){
//        Map<String, Object> params = new HashMap<>();
//        //定义该队列中消息的生存时间 单位毫秒 生存时间最终对应业务的延迟执行时间
//        params.put("x-message-ttl",15 * 60 * 1000);
//        // x-dead-letter-exchange 属性用于声明死信转发到的交换机
//        params.put("x-dead-letter-exchange", "order_check_exchange");
//        // x-dead-letter-routing-key 声明了这些死信在转发时携带的路由键名称。
//        params.put("x-dead-letter-routing-key", "memberOrder");
//        return new Queue("memberOrder_check_delay_queue", true, false, false, params);
//    }

    @Bean
    public Queue serviceOrderCheckDelayQueue(){
        Map<String, Object> params = new HashMap<>();
        //定义该队列中消息的生存时间 单位毫秒 生存时间最终对应业务的延迟执行时间
        params.put("x-message-ttl",60 * 1000*15 );
        // x-dead-letter-exchange 属性用于声明死信转发到的交换机
        params.put("x-dead-letter-exchange", "service_order_check_exchange");
        // x-dead-letter-routing-key 声明了这些死信在转发时携带的路由键名称。
        params.put("x-dead-letter-routing-key", "serviceOrder");
        return new Queue("serviceOrder_check_delay_queue", true, false, false, params);
    }


}
